<?php
session_start();

/**
* Native Session Library
*
* @package Native Session
* @category Libraries
* @author Adam Griffiths
* @link http://nanoswift.co.uk
* @link http://freshpowered.com/docs/index.html
*
* Native Session library is a replacement for the CI Session Library.
* It utilizes native PHP sessions and doesn't save data in a cookie,
* leaving the program open to attack.
*/

class MY_Session extends CI_Session
{
	
	var $CI;
	
	/** 
	* Auth constructor PHP5
	*
	* @access public
	* @param string
	*/
	function MY_Session()
	{
		$this->CI =& get_instance();
	}
	
	/** 
	* Set userdata
	* 
	* Set userdata by passing the name to param 1, and the value to param 2
	* Alternatively, pass an array to param 1.
	*
	* @access public
	* @param string
	*/
	function set_userdata($name, $value = NULL)
	{
		if( ! is_array($name))
		{
			if($value === NULL)
			{
				show_error("Second parameter for set_userdata missing.");
			} // if
			else
			{
				if(isset($_SESSION[$name]))
				{
					unset($_SESSION[$name]);
				} // if
				$_SESSION[$name] = $value;
			} // else
		} // if
		else
		{
			foreach($name as $names => $key)
			{
				if(isset($_SESSION[$names]))
				{
					unset($_SESSION[$names]);
				}
				$_SESSION[$names] = $key;
			} // forech
		} //  else
	} // set_userdata
	
	
	/** 
	* Userdata
	* 
	* Can be used in two ways
	* -- To check whether a session item exists
	* -- To access the session item
	*
	* @access public
	* @param string
	* @return bool
	*/
	function userdata($item, $string = NULL)
	{
		if( ! $string === NULL)
		{
			if( ! isset($_SESSION[$item]))
			{
				return FALSE;
			} // if
			else
			{
				return TRUE;
			} // else
		} // if
		else
		{
			if( ! isset($_SESSION[$item]))
			{
				return FALSE;
			} // if
			else
			{
				return $_SESSION[$item];
			} // else
		} // else
	} // userdata
	
	
	/** 
	* Unset userdata
	* 
	* Unsets the userdata by passing the name of the session to the function.
	* Also accepts an array.
	*
	* @access public
	* @param string
	*/
	function unset_userdata($userdata)
	{
		if( ! is_array($userdata))
		{
			unset($_SESSION[$userdata]);
		} // if
		else
		{
			foreach($userdata as $item)
			{
				unset($_SESSION[$item]);
			} // foreach
		} // else
	} // unset_userdata
	
	/** 
	* Session destroy
	* 
	* Destroys all session data.
	*
	* @access public
	*/
	function sess_destroy()
	{
		session_destroy();
	} // session_destroy
	
}

/* End of file Session.php */
/* Location: application/libraries/Session.php */